package com.hongxun.design.ui.dialogstyle;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.hongxun.design.R;


/**
 *
 *
 */
public class ProgressLoadingDialog extends ProgressDialog {

    private AnimationDrawable mAnimation;
    private Context mContext;
    private ImageView mImageView;
    private String mLoadingTip;
    private TextView mLoadingTv;
    private int count = 0;
    private String oldLoadingTip;
    private int mResid;

    public ProgressLoadingDialog(Context context, String content, int id) {
        super(context, R.style.Translucent_NoTitle);
        this.mContext = context;
        this.mLoadingTip = content;
        this.mResid = id;
        setCanceledOnTouchOutside(true);


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

    private void initData() {
       // mImageView.setMovieResource(mResid);
        mImageView.setBackgroundResource(mResid);
        // 通过ImageView对象拿到背景显示的AnimationDrawable
//        mAnimation = (AnimationDrawable) mImageView.getBackground();
//        // 为了防止在onCreate方法中只显示第一帧的解决方案之一
//        mImageView.post(new Runnable() {
//            @Override
//            public void run() {
//                mAnimation.start();
//
//            }
//        });
//        mLoadingTv.setText(mLoadingTip);

    }

    public void setContent(String str) {
        mLoadingTv.setText(str);
    }

    private void initView() {
        setContentView(R.layout.dialog_progress);
        mLoadingTv = (TextView) findViewById(R.id.loadingTv);
       // mImageView = (PowerImageView) findViewById(R.id.loadingIv);
        mImageView = (ImageView) findViewById(R.id.loadingIv);

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        //mAnimation.start();
        super.onWindowFocusChanged(hasFocus);
    }
}
